<div class="row">
	<div class="col-md-12">
		<a class="btn btn-success btn-sm" role="button" data-toggle="collapse" href="#filter" aria-expanded="false" aria-controls="filter" style="margin-bottom: 10px;">
			筛选
			<i class="icon-double-angle-down icon-large"></i>
		</a>
		<div class="collapse" id="filter">
			<div class="row">
				<form class="filter-form" action="${request.contextPath}/cw/for-payout-confirm" method="post">
					<div class="col-md-4">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div style="width: 60px;">合同编号</div>
								</div>
								<input type="text" class="form-control input-sm encode-no" name="cNo" value="${cNo}" />
							</div>
						</div>
					</div>
					<div class="col-md-4">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div style="width: 60px;">合同名称</div>
								</div>
								<input type="text" class="form-control input-sm" name="cName" value="${cName}" />
							</div>
						</div>
					</div>
					<div class="col-md-4">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div style="width: 60px;">收款单位</div>
								</div>
								<input type="text" class="form-control input-sm" name="mSource" value="${mSource}" />
							</div>
						</div>
					</div>
					<div class="col-md-4">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div style="width: 60px;">确认状态</div>
								</div>
								<select class="form-control input-sm" name="confirm">
									<option value=""${(!confirm??)?string(' selected','')}></option>
									<option value="false"${(confirm??&&!confirm)?string(' selected','')}>未确认</option>
									<option value="true"${(confirm??&&confirm)?string(' selected','')}>已确认</option>
								</select>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="btn btn-danger btn-sm filter-search">查询</div>
						<div class="btn btn-default btn-sm filter-reset">重置</div>
					</div>
					<div class="col-md-12">&nbsp;</div>
				</form>
			</div>
		</div>
	</div>
</div>

<table class="payout-for-confirm-list" data-page="${page!'1'}" data-count="${count!'0'}" data-page-size="${pageSize!'30'}">
	<tr class="title-row">
		<th class="text-center" width="60"></th>
		<th class="text-center" width="45">序号</th>
		<th class="text-center">合同名称</th>
		<th class="text-center">合同编号</th>
		<th class="text-center">支出名目</th>
		<th class="text-center">支出时间</th>
		<th class="text-center">金额（元）</th>
		<th class="text-center">支出单位</th>
		<th class="text-center">收款单位</th>
		<th class="text-center">备注</th>
	</tr>
	<#if data??> <#list data as c>
	<tr data-id="${c[8]}" style="cursor: pointer;" class="${((c[12]?? && c[12])?string('confirmed',''))!''}">
		<td class="text-center"><#if !c[12]?? && !c[12]>
			<div class="btn btn-danger btn-xs confirm-btn" data-id="${c[9]}">确认</div><#else><span class="text-danger">已确认</span></#if>
		</td>
		<td class="text-center item-cell">${c_index+1}</td>
		<td class="text-center item-cell">${c[4]}</td>
		<td class="text-center item-cell">${c[10]}</td>
		<td class="text-center item-cell">${c[0]}</td>
		<td class="text-center item-cell">${(c[1]?string('yyyy-MM-dd'))!'-'}</td>
		<td class="text-center item-cell">${(c[2]?string('currency'))!'-'}</td>
		<td class="text-center item-cell">${(c[5].collection?string(c[7], c[6]))!''}</td>
		<td class="text-center item-cell">${c[11]}</td>
		<td class="text-center item-cell">${c[3]}</td>
	</tr>
	</#list> </#if>
</table>
<!-- <script src="${request.contextPath}/js/suredy-list.js"></script>
<script src="${request.contextPath}/core/js/jquery.form.js"></script>
<script src="${request.contextPath}/app/js/encode-no.js"></script> -->

<script type="text/javascript">
	$('tr.confirmed td.item-cell').css('color', '#ccc');

	require([ 'suredyList', 'jqueryForm' ], function(List) {
		var doSearch = function(page, pageSize) {
			var form = $('form.filter-form');

			form.ajaxSubmit({
				dataType : 'html',
				data : {
					page : page,
					pageSize : pageSize
				},
				success : function(html, textStatus, jqXHR) {
					if (!html)
						return false;

					$('div.suredy-content').html(html);
				},
				error : function(jqXHR, textStatus, errorThrown) {
					return false;
				}
			});
		};

		List('table.payout-for-confirm-list', {
			header : false,
			paginate : function(page, pageSize, key) {
				doSearch(page, pageSize);
			}
		});

		$('table.payout-for-confirm-list td.item-cell').on('click', function() {
			var $this = $(this);
			var id = $this.parent().data('id');
			window.open('${request.contextPath}/contract/view/' + id + '/%23tab-head8', '_blank');
		});

		$('table.payout-for-confirm-list .confirm-btn').on('click', function() {
			if (!confirm('是否确认操作？')) {
				return false;
			}

			var $this = $(this);
			var id = $this.data('id');

			$.ajax({
				url : '${request.contextPath}/cw/confirm-payout/' + id,
				type : 'post',
				dataType : 'json',
				success : function(result, textStatus, jqXHR) {
					if (!result || !result.success) {
						var msg = (result && result.msg) || '确认失败！';
						alert(msg);
						return false;
					}

					Suredy.loadContent('${request.contextPath}/cw/for-payout-confirm')
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('确认失败！\n\n' + errorThrown);
				}
			});
		});

		$('form.filter-form .btn.filter-search').on('click', function() {
			doSearch(1, $('table.payout-for-confirm-list').data('page-size'));
		});

		$('form.filter-form .btn.filter-reset').on('click', function() {
			$('form.filter-form input').val('');
			$('form.filter-form option:first-child').prop('selected', true);
		});
	});
</script>
